package com.itheima.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeMap;

public class Test003 {
    public static void main(String[] args) {
        //请编写斗地主洗牌发牌程序
        //定义四个花色;
        String[] color = {"♥", "♦", "♠", "♣"};
        //定义十三个数字;
        String[] num = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //创建一个集合;
        TreeMap<Integer, String> map = new TreeMap<>();
        //创建一个单列集合;
        ArrayList<Integer> list = new ArrayList<>();
        //给集合添加52牌
        int count = 1;
        for (String s : num) {
            for (String s1 : color) {
                map.put(count, s + s1);
                list.add(count);
                count++;
            }
        }
        //存放大王小王;
        map.put(count, "小王");
        list.add(count);
        count++;
        map.put(count, "大王");
        list.add(count);
        //牌添加完成;
        //洗牌;
        Collections.shuffle(list);
        //发牌,因为是有三个人打牌,还有一个底牌,所以需要定义四个集合来存放;
        ArrayList<Integer> list01 = new ArrayList<>();
        ArrayList<Integer> list02 = new ArrayList<>();
        ArrayList<Integer> list03 = new ArrayList<>();
        ArrayList<Integer> list04 = new ArrayList<>();
        //遍历集合,因为底牌需要留三张,所以要留三张;
        for (int i = 0; i < list.size() - 3; i++) {
            //取出集合中的每一张牌;
            Integer pai = list.get(i);
            //进行判断;
            if (i % 3 == 0) {
                list01.add(pai);
            } else if (i % 3 == 1) {
                list02.add(pai);
            } else {
                list03.add(pai);
            }
        }
        //将留的三张牌添加到集合当中;
        for (int i = list.size() - 3; i < list.size(); i++) {
            Integer s = list.get(i);
            list04.add(s);
        }
        //对牌进行排序;
        Collections.sort(list01);
        Collections.sort(list02);
        Collections.sort(list03);
        Collections.sort(list04);
        //看牌;
        /*
        System.out.print("一号的牌:");
        for (Integer i : list01) {
            String s = map.get(i);
            System.out.print(s+" ");
        }
        System.out.println();
        System.out.print("二号的牌:");
        for (Integer i : list02) {
            String s = map.get(i);
            System.out.print(s+" ");
        }
        System.out.println();
        System.out.print("三号的牌:");
        for (Integer i : list03) {
            String s = map.get(i);
            System.out.print(s+" ");
        }
        System.out.println();
        System.out.print("底牌:");
        for (Integer i : list04) {
            String s = map.get(i);
            System.out.print(s+" ");
        }

         */
        look("一号",list01,map);
        look("二号",list02,map);
        look("三号",list03,map);
        look("底牌",list04,map);


    }
    public static void look(String name , ArrayList<Integer> list,TreeMap<Integer,String> map){
        System.out.println();
        System.out.print(name+":");
        for (Integer i : list) {
            String s = map.get(i);
            System.out.print(s+" ");
        }
    }


}
